#import "FromNativePlugin.h"

@implementation FromNativePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    FlutterMethodChannel* channel = [FlutterMethodChannel
                                     methodChannelWithName:@"from_native"
                                     binaryMessenger:[registrar messenger]];
    FromNativePlugin* instance = [[FromNativePlugin alloc] init];
    [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    if (NO) {
    } else if ([@"getPlatformVersion" isEqualToString:call.method]) {
        result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
    } else if ([@"platformString" isEqualToString:call.method]) {
        NSDictionary *info = NSBundle.mainBundle.infoDictionary;
        NSString *appName = info[@"CFBundleDisplayName"];
        NSString *appVersion = info[@"CFBundleShortVersionString"];
        NSString *str = [NSString stringWithFormat:@"%@ %@", appName, appVersion];
        result(str);
    } else if ([@"externalResourceInfo" isEqualToString:call.method]) {
        NSString *path = [NSBundle.mainBundle pathForResource:@"a.txt" ofType:nil];
        NSError *error = nil;
        NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
        if (!str) {
            str = error.localizedDescription;
        }
        result(str);
    } else {
        result(FlutterMethodNotImplemented);
    }
}

@end
